package org.edu2maxgadgets.client;

import com.google.gwt.gadgets.client.Gadget;
import com.google.gwt.gadgets.client.UserPreferences;
import com.google.gwt.gadgets.client.Gadget.ModulePrefs;
import com.google.gwt.gadgets.client.Gadget.UseLongManifestName;
import com.google.gwt.gadgets.client.Gadget.AllowHtmlQuirksMode;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.DragAppearance;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.layout.VStack;

@ModulePrefs(title = "Order Mania", author = "Juan E. Coronado, PhD", author_email = "teachingbioinjc@gmail.com")
@UseLongManifestName(false)
@AllowHtmlQuirksMode(false)
/**
 * Gadgets classes define <code>init()</co de>.
 */
public class OrderDnd extends Gadget<UserPreferences> {

	@Override
	protected void init(UserPreferences preferences) {
		DropBox gray = new DropBox("images/edges/gray/6.png");
		gray.addMember(new DragPiece("images/cars/alfa_romeo.jpg", "b"));
		gray.addMember(new DragPiece("images/cars/carrera_gt.jpg", "g"));
		gray.addMember(new DragPiece("images/cars/saleen.jpg", "y"));
		gray.setDropTypes("b", "g", "y");

		DropBox blue = new DropBox("images/edges/blue/6.png");
		blue.setDropTypes("b");

		DropBox green = new DropBox("images/edges/green/6.png");
		green.setDropTypes("g");

		HStack hStack = new HStack(20);
		hStack.addMember(gray);
		hStack.addMember(blue);
		hStack.addMember(green);

		hStack.draw();

	}

	private class DropBox extends VStack {
		public DropBox() {
			setShowEdges(true);
			setMembersMargin(10);
			setLayoutMargin(10);
			setCanAcceptDrop(true);
			setAnimateMembers(true);
			setDropLineThickness(4);
			setAutoHeight();
		}

		public DropBox(String edgeImage) {
			this();
			setEdgeImage(edgeImage);
		}
	}

	private class DragPiece extends Img {
		public DragPiece() {
			setWidth(48);
			setHeight(48);
			setLayoutAlign(Alignment.CENTER);
			setCanDragReposition(true);
			setCanDrop(true);
			setDragAppearance(DragAppearance.TARGET);
			setAppImgDir("images/pieces/48/");
		}

		public DragPiece(String src, String dragType) {
			this();
			setSrc(src);
			setDragType(dragType);
		}
	}

}
